﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Functional
{
    public class NBody
    {
        public static TResult[] PairResults<TParticle, TResult>(TParticle[] particles, Func<TParticle, TParticle, TResult> action)
        {
            List<TResult> outResults = new List<TResult>();
            TResult lResult;
            Int32 L1, L2;
            for (L1 = 0; L1 < particles.Length; L1++)
            {
                for (L2 = L1; L2 < particles.Length; L2++)
                {
                    lResult = action(particles[L2], particles[L1]);
                    outResults.Add(lResult);
                }
            }
            return outResults.ToArray();
        }
    }
}
